package com.jds.test.bio.p10;

/**
 *https://www.cnblogs.com/silyvin/articles/12055397.html
 * Created by joyce on 2019/11/26.
 */
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static final int PORT = 12123;
    public static final int BUFFER_SIZE = 1024;

    public static void main(String [] f) throws IOException, InterruptedException {
        new Server().server();
    }

    //服务端代码
    public void server() throws IOException, InterruptedException{
        ServerSocket ss = new ServerSocket(PORT);
        while(true) {
            Socket s = ss.accept();

            s.getOutputStream().write("hello ".getBytes());
            s.getOutputStream().flush();

            /**
             * 以上代码不会发送fin包回应客户端的fin包
             */
            while (s.getInputStream().read(new byte[BUFFER_SIZE]) != -1) {
                ;
            };
            /**
             * 显示close，发出fin包
             */
            s.close();
        }
    }
}